//
//  RCacheTableViewCell.m
//  iMoive
//
//  Created by 侯伟 on 2021/9/17.
//

#import "RCacheTableViewCell.h"
#import <SDWebImage/UIImageView+WebCache.h>

#import "RCacheObj.h"

@interface RCacheTableViewCell ()
/// 显示内容视图
@property(nonatomic,weak) MyRelativeLayout* contentLayout;

@end

@implementation RCacheTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        
        self.backgroundColor = UIColor.whiteColor;
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self initSubViews];
    }
    return self;
}


- (void)initSubViews{
    
    MyRelativeLayout *contentLayout = [MyRelativeLayout new];
    contentLayout.padding = UIEdgeInsetsMake(16, 16, 16, 16);
    contentLayout.myMargin = 0;
    contentLayout.myHeight = MyLayoutSize.wrap;
    [self.contentView addSubview:contentLayout];
    _contentLayout = contentLayout;
    
    UIButton* selectBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [selectBtn setImage:[UIImage imageNamed:@"common_select_n"] forState:UIControlStateNormal];
    [selectBtn setImage:[UIImage imageNamed:@"common_select_h"] forState:UIControlStateSelected];
    selectBtn.mySize = CGSizeMake(PX(28), PX(28));
    selectBtn.myCenterY = 0;
    selectBtn.myLeft = 0;
    [selectBtn addTarget:self action:@selector(selectClick:) forControlEvents:UIControlEventTouchUpInside];
    [contentLayout addSubview:selectBtn];
    _selectBtn = selectBtn;
    
    UIImageView* coverImage = [[UIImageView alloc] init];
    coverImage.backgroundColor = UIColor.blackColor;
    coverImage.mySize = CGSizeMake(PX(120), PX(90));
    coverImage.contentMode = UIViewContentModeScaleAspectFit;
    coverImage.leftPos.equalTo(selectBtn.rightPos).offset(8.0);
    coverImage.myVertMargin = 0;
    [contentLayout addSubview:coverImage];
    _coverImage = coverImage;
    
    UIProgressView* progress = [UIProgressView new];
    progress.progressTintColor = COLOR_THEME;
    progress.trackTintColor = COLOR_GRAY_BASE;
    progress.myHeight = PX(4);
    progress.bottomPos.equalTo(coverImage.bottomPos).offset(0);
    progress.leftPos.equalTo(coverImage.leftPos).offset(0);
    progress.rightPos.equalTo(coverImage.rightPos).offset(0);
    progress.myBottom = 0;
    [contentLayout addSubview:progress];
    _process = progress;
    
    
    UIButton* playBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [playBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateNormal];
    [playBtn setImage:[UIImage imageNamed:@"common_close"] forState:UIControlStateSelected];
    playBtn.centerXPos.equalTo(coverImage.centerXPos);
    playBtn.centerYPos.equalTo(coverImage.centerYPos);
    playBtn.mySize = CGSizeMake(PX(24), PX(24));
    playBtn.userInteractionEnabled = NO;
    [contentLayout addSubview:playBtn];
    _playBtn = playBtn;
    
    UILabel* nameLb = [UILabel lableWithFont:FONT_FIT(15) color:COLOR_BLACK_DARK text:@"影片名称"];
    nameLb.leftPos.equalTo(coverImage.rightPos).offset(10);
    nameLb.myTop = 0;
    [contentLayout addSubview:nameLb];
    _nameLb = nameLb;
    
    UILabel* stateLb = [UILabel lableWithFont:FONT_FIT(12) color:COLOR_GRAY_BASE text:@"暂停"];
    stateLb.leftPos.equalTo(coverImage.rightPos).offset(10);
    stateLb.myBottom = 0;
    [contentLayout addSubview:stateLb];
    _stateLb = stateLb;
    
    UILabel* sizeLb = [UILabel lableWithFont:FONT_FIT(12) color:COLOR_GRAY_BASE text:@"0.0M"];
    sizeLb.leftPos.equalTo(stateLb.rightPos).offset(10);
    sizeLb.myBottom = 0;
    [contentLayout addSubview:sizeLb];
    _sizeLb = sizeLb;
}

- (void)selectClick:(UIButton*)sender{
    sender.selected = !sender.selected;

    if(self.selectBlock){
        self.selectBlock(sender.selected);
    }
}
@end
